package sort;

import java.util.Arrays;

public class InsertSort implements MySort {
    public static void main(String[] args) {
        int a[] = {55,78,35,29,156,88,66};
        //int a[] = {1,2,3,4,5,6,7};
        InsertSort insertSort = new InsertSort();
        insertSort.sort(a);
        System.out.println(Arrays.toString(a));
    }

    @Override
    public void sort(int[] a) {
        int insertIndex = 0;
        int temp;
        for(int i = 1;i<a.length;i++){
            insertIndex = i;
            temp = a[i];
            while(insertIndex>=1&&a[insertIndex-1]>temp){
                a[insertIndex] = a[insertIndex-1];
                insertIndex--;
            }
            a[insertIndex] = temp;
        }
    }
}
